"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".

Replace these with more appropriate tests for your application.
"""

from django.test import TestCase

orig = """
=== edit Article ===

But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born 

and I will give you a complete account of the system, 

and expound the actual teachings of the great explorer of the truth, 

the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? 

+++++some pluses+++++++
@@@@@@@@some ats@@@@@@@@@@@

But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?

"""[:255] #stupid old versions of mysql

edit = orig.replace('the', 'teh')
edit = edit[:150] + edit[200:]

edit2 = edit.replace('pleasure', 'yummy cookies').replace('man', 'woman')
edit2 = edit2.replace("@", "at at")



class PatchTestCase(TestCase):
    from pprint import pprint
    
    def setUp(self):
        p1 = Patch(orig, edit)
        p2 = Patch(edit, edit2)
        p3 = Patch(edit2, orig)
        
        p1_serialized = Patch(str(p1))
        p2_serialized = Patch(str(p2))
        p3_serialized = Patch(str(p3))
    
    def assert_patch_works(patch,orig,edit):
        self.assertEquals(Patch(edit,patch.apply(orig)),[])
            
    def dump_versions(self):
        print 'orig:'
        print orig
        print
        print 'edit:'
        print edit
        print
        print 'edit2:'
        print edit2
        print
        
    def single_test(self):
        self.assert_patch_works(p1, orig, edit)
        self.assert_patch_works(p2, edit, edit2)
        self.assert_patch_works(p3, edit2, orig)
        
        
    def serialize_test(self):
        self.assert_patch_works(p1_serialized, orig, edit)
        self.assert_patch_works(p2_serialized, orig, edit)
        self.assert_patch_works(p3_serialized, orig, edit)
        
    def add_test(self):
        self.assert_patch_works(p1 + p2, orig, edit2)
        self.assert_patch_works(p2 + p3, edit, orig)
        self.assert_patch_works(p3 + p1, edit2, edit)
    
